package com.taxsystem.gaozhuanglin.booking;

import java.util.concurrent.ExecutionException;

import com.main.taxsystem.R;
import com.taxsystem.gaozhuanglin.bookingtool.TicketItem;
import com.taxsystem.tool.HttpUtil;

import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class TicketItemActivity extends Activity {
	
	//LinearLayout ll;
	EditText psEdit;
	Button b1;
	
	String [] ticketItemName = {"取款","缴税"};
	private int [] ticketItemIds = {1,2};
	//private int areaId;
	public final static String RECI_COAST_TICKETITEM = "TICKETITEM_LIST";
	private final static String url = ""; 
	private static int [] colors = {0xff3ddc7b, 0xfff8b444, 0xffdd57ab, 0xff4db3ff, 0xfff35b59};
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ticket_item_2);
		
		//ll = (LinearLayout)findViewById(R.id.linear);
		psEdit = (EditText)findViewById(R.id.remark);
		b1 = (Button)findViewById(R.id.green_line);
		b1.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent_next = new Intent(TicketItemActivity.this, CalendarActivity.class);
				startActivity(intent_next);
			}
		});
		
		//areaId = getIntent().getIntExtra("areaId", 1);
		
		
		//IntentFilter filter = new IntentFilter(RECI_COAST_TICKETITEM);
		//BroadcastReceiver myRecive = new TicketItemRecive();
		//registerReceiver(myRecive, filter);
		
		Thread ticketItemThread = new Thread() 
		{

			@Override
			public void run() 
			{
				Intent intent = new Intent(RECI_COAST_TICKETITEM);
				try {
					//获取服务器返回的信息
					String reslut = HttpUtil
							.getRequest(url);
					intent.putExtra("ticketItemName_list", reslut);
					//发送广播
					sendBroadcast(intent);
				} catch (InterruptedException e) {
					e.printStackTrace();
				} catch (ExecutionException e) {
					e.printStackTrace();
				}
			}

		};
		//ticketItemThread.start();
		
		/*if(ticketItemName==null)
		{Log.d("booking", "空指针异常");}
		else
		{
		ArrayAdapter<String> ticketItemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ticketItemName);
		ticketItemList.setAdapter(ticketItemAdapter);
		
		ticketItemList.setOnItemClickListener(new OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int position,
					long id) {
				// TODO Auto-generated method stub
				Intent intent2 = new Intent(TicketItemActivity.this, CalendarActivity.class);
				int result2 = ticketItemIds[position];
				intent2.putExtra("areaId", areaId);
				intent2.putExtra("ticketItemId", result2);
				String str = psEdit.getText().toString();
				if(str!=null)
				{intent2.putExtra("bookremarks", str);}
				startActivity(intent2);
			}
			
		});
		}*/
	}
	
	/*private class TicketItemRecive extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			try
			{
				JSONObject json = new JSONObject(intent.getStringExtra("ticketItemName_list"));
				JSONArray jsonArray = json.getJSONArray("Data");
				TicketItem [] ticketItemArray = new TicketItem[jsonArray.length()];
				ticketItemName = new String[jsonArray.length()];
				ticketItemIds = new int[jsonArray.length()];
				for(int i = 0; i < jsonArray.length(); i++)
				{
					JSONObject j1 = (JSONObject)jsonArray.get(i);
					ticketItemArray[i].setSettingId(j1.getInt("settingId"));
					ticketItemArray[i].setAreaId(j1.getInt("areaId"));
					ticketItemArray[i].setTicketItemName(j1.getString("ticketItemName"));
					ticketItemArray[i].setTicketItemId(j1.getInt("ticketItemId"));
					ticketItemName[i] = j1.getString("ticketItemName");
					ticketItemIds[i] = j1.getInt("ticketItemId");
				}
				
				//添加业务按钮
				for(int j = 0; j< jsonArray.length(); j++)
				{
					Button bn = new Button(TicketItemActivity.this);
					bn.setText(ticketItemName[j]);
					bn.setTextSize(20);
					bn.setTextColor(0xffffffff);
					//bn.setLayoutParams(new ViewGroup.LayoutParams(
						//	ViewGroup.LayoutParams.MATCH_PARENT,
							//ViewGroup.LayoutParams.WRAP_CONTENT));
					bn.setBackgroundColor(colors[j%5]);
					LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
					lp.setMargins(0, 0, 0, 20);
					bn.setLayoutParams(lp);
					bn.setOnClickListener(new OnClickListener()
					{

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							Intent intent1 = new Intent(TicketItemActivity.this, CalendarActivity.class);
							//传输参数
							startActivity(intent1);
						}});
					ll.addView(bn);
				}
			}
			
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
	}*/
	
}
